#!/bin/sh
project_name="$1"
if [[ $project_name == "" ]]
then
    echo "缺少项目名称"
    exit
fi

# 部署时变量OCEAN_ENV会传进来
case $OCEAN_ENV in
    Development)
        project_env="dev"
        ;;
    Test)
        project_env="test"
        ;;
    Simulation)
        project_env="simu"
        ;;
    Preview)
        project_env="prod"
        ;;
    Production)
        project_env="prod"
        ;;
    *)
        echo "环境参数错误. e.g. Development Test Simulation Production"
        exit
esac

echo "Environment: "$project_env
echo "Project: "$project_name


project_dir=$(cd $(dirname $0); pwd)
cd $project_dir/../

config_path=/app/src/$project_name/conf/app.conf

# 开发环境
if [[ $OCEAN_ENV == "Development" ]]
then
    echo "开发环境目前不需要构建镜像"
    cp environments/dev/app.conf $config_path
   # exit
fi

# 测试环境
if [[ $OCEAN_ENV == "Test" ]]
then
    echo "测试环境替换配置文件"
    cp environments/test/app.conf $config_path
fi


# 仿真环境
if [[ $OCEAN_ENV == "Simulation" ]]
then
    echo "仿真环境替换配置文件"
    cp /mnt/config/app.conf $config_path
fi

# 预发布
if [[ $OCEAN_ENV == "Preview" ]]
then
    echo "仿真环境替换配置文件"
    cp /mnt/config/app.conf $config_path
fi


# 生产环境
if [[ $OCEAN_ENV == "Production" ]]
then
    echo "生产环境替换配置文件"
    cp /mnt/config/app.conf $config_path
fi

# 启动
mkdir logs
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
"$SCRIPTPATH/$project_name" -importPath $project_name/ -srcPath "$SCRIPTPATH/src" -runMode $project_env
